The growing use of web services and XML as a main source of web content has brought about the need for high levels of XSLT performance in concurrent environments. Certain syntax and semantics define templates that can be used with the Extensible Stylesheet Language (XSL), a stylesheet language for XML. These XSL templates, known collectively as XSLT, comprise a language for transforming XML documents between XML formats. In addition to XSLT, XSL includes a vocabulary for specifying XML formats. XSL can specify the style of an XML document by using XSLT. XSLT can describe how one XML document is transformed into another that uses the formatting vocabulary. XSLT can also be used independent of XSL. XSLT is not intended as a general-purpose XML transformation language, but is designed for transformations that are needed when XSLT is used as part of XSL.
A transformation in the XSLT language is expressed as a well-formed, conforming XML document. This can include both elements that are defined by XSLT and elements that are not defined by XSLT. XSLT-defined elements belong to a specific XML namespace, which can be referred to as an XSLT namespace.
A transformation expressed in XSLT can describe rules for transforming a source tree into a result tree. This transformation can be achieved by associating patterns with templates. A pattern can then be matched against elements in the source tree. A template is instantiated to create part of the result tree. The structure of the result tree can be different than that of the source tree. In constructing the result tree, elements from the source tree can be filtered and reordered into an arbitrary structure. A transformation expressed in XSLT is called a stylesheet, as the transformation functions as a stylesheet when XSLT is transforming into the XSL formatting vocabulary.
A stylesheet contains a set of template rules, with each template rule having two parts. One part is a pattern that is matched against nodes in the source tree, and the other part is a template that can be instantiated to form part of the result tree. This two-part approach allows a stylesheet to be applicable to a wide class of documents that have similar source tree structures.
A template is instantiated for a particular source element to create part of the result tree. The template can contain elements that specify literal result element structure, and can contain elements from the XSLT namespace. These elements can comprise instructions for creating result tree fragments. When a template is instantiated, each instruction is executed and replaced by the result tree fragment that it creates. Instructions can select and process descendant source elements. Processing a descendant element can create a result tree fragment by finding the applicable template rule and instantiating its template. Elements are only processed when they are selected by the execution of an instruction. The result tree is constructed by finding the template rule for the root node and instantiating its template. In the process of finding the applicable template rule, more than one template rule can have a pattern that matches a given element. However, only one template rule can be applied.
A single template can create structures of arbitrary complexity. A template can pull string values from arbitrary locations in the source tree. The template can generate structures that are repeated according to the occurrence of elements in the source tree. For simple transformations where the structure of the result tree does not depend on the structure of the source tree, a stylesheet can consist of a single template, which functions as a template for the complete result tree. Transformations on XML documents that represent data are often of this kind. XSLT allows a simplified syntax for such stylesheets.
A template is instantiated with respect to a current node and a current node list. Many XSLT operations are relative to the current node. During the instantiation of one of these instructions, the current node list can change to a new list of nodes and each member of this new list can sequentially become the current node. After the instantiation is complete, the current node and current node list revert to their pre-instantiated state.
Transformations for legacy systems can include XML data to be transformed, an XSL stylesheet, and an XSL transformer. Input data and a stylesheet are read into memory, parsed, and transformed into output XML data. While input XML data is highly volatile, XSL stylesheets can be stable in the production environment. This makes processing of XSL stylesheets a subject for optimization. Certain approaches can be used to improve the performance of a legacy XSLT. One approach is to read and keep an XSL stylesheet in memory for subsequent reuse. This approach reduces the input/output time necessary to get a stylesheet from the source. The source can be a file or a generic stream.
Preliminary parsing of a stylesheet can be placed into a tree for subsequent reuse. This saves time by avoiding the repetition of parsing by a transformer. For compiled stylesheets, a stylesheet can be compiled to Java bytecode which then performs a transformation. This can be a fast means of transportation. Modern XSL transformers, including Apache XALAN, offer ways to implement these optimization techniques. This optimization approach works fine for single user environments, but heavy-loaded server side applications and servers themselves add requirements for concurrent processing but do not wish to compromise throughput.